package com.tarena.day04_all;

import java.util.Scanner;

public class ScoreManager {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = createClassNumber();//目的：限制班级人数1——50之间
		String[] names = new String[num];
		double[] scores = new double[num];
		System.out.println("**********************欢迎登陆学员成绩管理系统**********************");
		start(names, scores);
	}
	public static void start(String[] names, double[] scores){
		Scanner sc = new Scanner(System.in);
		while(true){
			System.out.println("请选择功能：1——成绩录入，2——成绩列表，3——成绩查询，4——成绩统计，5——退出");
			String command = sc.next().trim();
			if(command.equals("1")){
				System.out.println("***********请录入学员成绩***********");
				inputScore(names, scores);
				System.out.println("-----------录入学员成绩完毕！----------");
			}else if(command.equals("2")){
				System.out.println("***********学员成绩列表***********");
				showScoreChart(names, scores);
				System.out.println("--------------------------------");
			}else if(command.equals("3")){
				System.out.println("请输入您要查找学员成绩的姓名：");
				String queryName = sc.next().trim();
				String message = checkScore(queryName, names, scores);
				System.out.println(message);
				System.out.println("------------------------------------");
			}else if(command.equals("4")){
				System.out.println("****************学员统计表******************");
				printGradeByScores(scores);
				System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
			}else if(command.equals("5")){
				String command01 = exitSystem();
				if(command01.equalsIgnoreCase("Y")){
					System.out.println("##################已经退出当前系统###################");
					break;
				}else if(command01.equalsIgnoreCase("N")){
					System.out.println("$$$$$$$$$$$$$$$$$$$——回到该系统——$$$$$$$$$$$$$$$$$$$$$$$$$$");
					continue;
				}
			}
		}
	}
	//6)退出当前系统
	public static String exitSystem(){
		Scanner sc = new Scanner(System.in);
		System.out.println("请问是否真的要退出该系统？是：Y！否：N");
		String command;
		while(true){
			command = sc.next().trim();
			if(command.equalsIgnoreCase("Y") || command.equalsIgnoreCase("N")){
				break;
			}
			System.out.println("输入错误，请从新输入命令，是/否：Y/N'''''''''''''''''''/./.");
		}
		return command;
	}
	//5)根据学员分数划分学生等级：
	public static void printGradeByScores(double[] scores){
		int a = 0, b = 0, c = 0, d = 0, e = 0;
		for(int i = 0; i < scores.length; i++){
			if(scores[i] >= 90){
				a++;
			}else if(scores[i] >= 80){
				b++;
			}else if(scores[i] >= 70){
				c++;
			}else if(scores[i] >= 60){
				d++;
			}else{
				e++;
			}
		}
		System.out.println("90——100分，优秀：" + a + "人");
		System.out.println("80——90分，良好：" + b + "人");
		System.out.println("70——80分，中等：" + c + "人");
		System.out.println("60——70分，及格：" + d + "人");
		System.out.println("60分以下，不及格：" + e + "人");
	}
	//4，根据学员姓名查找其对应的分数。
	public static String checkScore(String queryName, String[] names, double[] scores){
		String message = "";
		for(int i = 0; i < names.length; i++){
			if(queryName.equals(names[i])){
				message = "姓名：" + names[i] + "\t分数：" + scores[i];
				break;
			}else{
				message = "没有找到该学员";
			}
		}
		return message;
	}
	//3）显示班级学员的姓名和成绩
	public static void showScoreChart(String[] names, double[] scores){
		for(int i = 0; i < scores.length; i++){
			System.out.print((i + 1) + ") 姓名：" + names[i] + "\t成绩：" + scores[i] + "\r");
		}
	}
	//2）输入班级学员姓名和分数。
	public static void inputScore(String[] names, double[] scores){
		Scanner sc = new Scanner(System.in);
		for(int i = 0; i < scores.length; i++){
			System.out.print("请输入第" + (i + 1) + "的姓名:\t");
			names[i] = sc.next();
			System.out.print("\t请输入该学员的成绩：\t");
			scores[i] = sc.nextDouble();
			System.out.println();
		}
	}
	//1)创建班级：要求班级人数在（1——50）之间。
	public static int createClassNumber(){
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入班级学员人数(1——50)：");
		int num;
		do{
			num = sc.nextInt();
			if(num > 50 || num < 1){
				System.out.println("输入错误，请重新输入：");
			}
		}while(num > 50 || num < 1);
		return num;
	}
}
